Component({
  mixins: [],
  data: {
    imgHead:'https://rhi0.xiyun.net/zhuandian/image/',
  },
  props: {
    visible:{

    }
  },
  didMount() {
    my.getSystemInfo({
      success: (res) => {
        that.setData({
          'statusBarHeight': res.statusBarHeight,//状态栏高度 
          'titleBarHeight': res.titleBarHeight,//标题栏高度
          'navHeight': res.statusBarHeight + res.titleBarHeight, //导航栏高度
          'imgHeight': res.windowWidth * 0.86, //背景图片高度
          'toDaytui': res.windowWidth / 698 * 96 + 35,
          'toAdtui': res.windowWidth / 716 * 171,
        })
      }
    });
  },
  didUpdate() {},
  didUnmount() {},
  methods: {
    //是否能领金币
  enableLing(){
    let that = this;
    that.setData({
      title : that.data.title
    })
    // clearInterval(time);
    prmoseHttp.publicRequest(prmoseHttp.apiAddress.enable,{},1,'get').then(res=>{
      if(res.code == 200){
        
        if(res.data.enable == true){
          // title = '活跃金币'
          that.setData({
            enable:res.data.enable,
          })
        }else{
          let previousTime = parseInt(res.data.previousTime/1000);
          let nowTime = Date.parse(new Date(new Date))/1000;
          let overTime = nowTime - previousTime;
          that.countDown(overTime);
        }
      }else if(res.code == 408 || res.code == 405){
        that.GetAuthorize();
      }
    })
  },
    countDown(overTime){
      let that = this;
        //10分钟领取一次
        clearInterval(that.data.setInter);
        let remainTime = 1800 - overTime;
        let title = '';
        // that.countDown(overTime);
        let min = Math.floor(remainTime/60)
        let second = remainTime%60
        that.data.setInter = setInterval(() => {
          if(overTime < 1800){
            if(second > 1){
              second --
            }else{
              second = 59;
              min--
            }
            title = min+'分'+second+'秒'
            that.setData({
              title:title,
              enable:false,
            })
          }else{
            my.alert({
              title:'销毁'
            })
            title = '领取金币'
            clearInterval(that.data.setInter);
            that.setData({
              title:title,
              enable:true,
            })
          }
        }, 1000);
      },
    // },
   
     //领金币
  getClaim(){
    let that = this;
    that.setData({
      enable:false
    })
    let enable;
      // if(that.data.enable == true){
      prmoseHttp.encryRequest(prmoseHttp.apiAddress.claim,{},1,'get').then(res=>{
        if(res.code == 200){
          that.getCoinVoice();
          that.setData({
            enveOpened:true,
            currency:res.data,
            currencyType:2,
          })
          that.enableLing();
          that.getAccount();
          enable = true;
        }else if(res.code == 408 || res.code == 405){
          that.GetAuthorize();
          enable = false;
        }else{
          my.showToast({
            content:res.message
          });
          enable = false;
          // that.enableLing();
        }
        that.setData({
          enable:enable
        })
      })
      // }else{

      //   my.showToast({
      //     content:that.data.title+'后可领取'
      //   })
      // }
    // })
  },
  },
});
